package com.el.springboot.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.el.springboot.common.Result;
import com.el.springboot.entity.LoginLog;
import com.el.springboot.mapper.LoginLogMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api")
public class LoginLogController {
    @Resource
    private LoginLogMapper loginLogMapper;

    //查询列表
    @GetMapping("/logs")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           @RequestParam(defaultValue = "") String username) {
        QueryWrapper<LoginLog> queryWrapper = new QueryWrapper<>();
        // 查询
        queryWrapper.eq("status", 1);
        queryWrapper.orderByDesc("login_time");
        queryWrapper.like("username", username);
        //if (!"".equals(name)) {
        //    queryWrapper.like("name", name);
        //}
        return Result.success(loginLogMapper.selectPage(new Page<>(pageNum, pageSize),queryWrapper));
    }
}
